package com.lisynet.tools.mytools.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.lisynet.tools.mytools.entity.OpmSyncRecord;
import com.lisynet.tools.mytools.entity.User;
import com.lisynet.tools.mytools.mapper.OpmSyncRecordMapper;
import com.lisynet.tools.mytools.service.IOpmSyncRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lisynet.tools.mytools.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lisy
 * @since 2022-01-18
 */
@Service
public class OpmSyncRecordServiceImpl extends ServiceImpl<OpmSyncRecordMapper, OpmSyncRecord> implements IOpmSyncRecordService {
    @Resource
    private IUserService userService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRecord(OpmSyncRecord record) {
        this.baseMapper.insert(record);
        User user = User.builder().
                name(IdUtil.simpleUUID())
                .age(RandomUtil.randomInt(20,99))
                .build();
        userService.addUser(user);
    }
}
